<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>demo sc - 系统工作台</title>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/vue.min.js"></script>
    <link rel="stylesheet" href="css/frame.css">
    <script type="text/javascript">
        $(document).ready(function () {
            $.ajax({
                url: "/api/user/info" + "/" + getCookie('auth'),
                success: function (result) {
                    console.log(arguments);
                    $("#welcome").text(result + "，欢迎登录系统！")
                },
                error: function (xhr) {
                    if (xhr.status == "401") {
                        alert(xhr.statusText + ": " + xhr.responseText);
                        location.href = "login.html";
                    }
                }
            });

            $("#logout").bind("click", () => {
                $.ajax({
                    url: "/api/user/logout",
                    success: () => {
                        location.href = "login.html";
                    }
                });
            });

            function getList() {
                setTimeout(() => {
                    new Vue({
                        el: "#Vue_ele",
                        data: {
                            list: []
                        },
                        created: function () {
                            var that = this;
                            $.ajax({
                                url: "/api/log/authcode/20/1",
                                success: (result) => {
                                    that.list = result.content;
                                }
                            })
                        }
                    });
                }, 1000);
            };

            function getCookie(sName) {
                console.log('开始获取token');
                console.log(sName);
                var aCookie = document.cookie.split("; ");
                for (var i = 0; i < aCookie.length; i++) {
                    var aCrumb = aCookie[i].split("=");
                    if (sName == aCrumb[0])
                        return unescape(aCrumb[1]);
                }
                return null;
            }
        });
    </script>
</head>

<body>
<header class="header">
    <nav>
        <div id="welcome" class="welcome"></div>
        <div class="logout">
            <a id="logout">注销</a>
        </div>
    </nav>
</header>

<div id="Vue_ele" class="container">
    <table>
        <tr>
            <th>序号</th>
            <th>邮箱</th>
            <th>验证码</th>
            <th>创建时间</th>
            <th>过期时间</th>
        </tr>
        <tbody>
        <tr v-for="item in list">
            <td v-text="item.id"></td>
            <td v-text="item.email"></td>
            <td v-text="item.code"></td>
            <td v-text="item.createtime"></td>
            <td v-text="item.expiretime"></td>
        </tr>
        </tbody>
    </table>
</div>
</body>

</html>